package com.esri.core.tasks.ags.geoprocessing;

import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.io.handler.h;
import com.esri.core.internal.io.handler.n;
import com.esri.core.io.UserCredentials;
import java.util.HashMap;
import java.util.List;

/* loaded from: classes.dex */
public class Geoprocessor {
    private UserCredentials credentials;
    private SpatialReference outSR;
    private SpatialReference processSR;
    private String url;

    public Geoprocessor(String str) {
        this.url = str;
    }

    public Geoprocessor(String str, UserCredentials userCredentials) {
        this.url = str;
        this.credentials = userCredentials == null ? null : userCredentials.getCopy();
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String str) {
        this.url = str;
    }

    public SpatialReference getOutSR() {
        return this.outSR;
    }

    public SpatialReference getProcessSR() {
        return this.processSR;
    }

    public void setOutSR(SpatialReference spatialReference) {
        this.outSR = spatialReference;
    }

    public void setProcessSR(SpatialReference spatialReference) {
        this.processSR = spatialReference;
    }

    public GPResultResource execute(List<GPParameter> list) throws Exception {
        GPTaskParameters gPTaskParameters = new GPTaskParameters(list);
        gPTaskParameters.setOutSR(this.outSR);
        gPTaskParameters.setProcessSR(this.processSR);
        return new GPExecuteTask(gPTaskParameters, this.url, this.credentials).executeInternal();
    }

    public GPJobResource submitJob(List<GPParameter> list) throws Exception {
        GPTaskParameters gPTaskParameters = new GPTaskParameters(list);
        gPTaskParameters.setOutSR(this.outSR);
        gPTaskParameters.setProcessSR(this.processSR);
        gPTaskParameters.setPollForCompletion(false);
        return new GPSubmitJobAndPollTask(gPTaskParameters, this.url, this.credentials).execute();
    }

    public GPJobResource checkJobStatus(String str) throws Exception {
        return new GPJobStatusTask(new GPJobStatusParameters(str), this.url, this.credentials).execute();
    }

    public GPParameter getResultData(String str, String str2) throws Exception {
        return getResult(str, str2, false);
    }

    public GPParameter getResultImage(String str, String str2) throws Exception {
        return getResult(str, str2, true);
    }

    private GPParameter getResult(String str, String str2, boolean z) throws Exception {
        HashMap hashMap = new HashMap();
        if (!z) {
            hashMap.put("returnType", "data");
        }
        SpatialReference spatialReference = this.outSR;
        if (spatialReference != null && spatialReference.getID() >= 0) {
            hashMap.put("outSR", String.valueOf(this.outSR.getID()));
        }
        return GPParameter.createFromJson(h.a(this.url + "/jobs/" + str + "/results/" + str2, hashMap, n.a(this.url, this.credentials)));
    }
}
